package ace.module.oauth2.server.core.impl.authentication.ace.service.impl;

import ace.module.common.core.impl.properties.ModuleCommonSecurityProperties;
import ace.module.oauth2.server.core.impl.authentication.ace.service.AceAuthenticationService;
import org.springframework.security.oauth2.core.AuthorizationGrantType;
import org.springframework.stereotype.Component;
import org.springframework.util.function.SingletonSupplier;

/**
 * .
 * @author Caspar
 *
 */

@Component
public class AceAuthenticationServiceImpl implements AceAuthenticationService {

  private final ModuleCommonSecurityProperties moduleCommonSecurityProperties;
  private final SingletonSupplier<AuthorizationGrantType> aceAuthorizationGrantTypeSingletonSupplier;

  public AceAuthenticationServiceImpl(ModuleCommonSecurityProperties moduleCommonSecurityProperties) {
    this.moduleCommonSecurityProperties = moduleCommonSecurityProperties;
    this.aceAuthorizationGrantTypeSingletonSupplier = SingletonSupplier.of(() -> new AuthorizationGrantType(this.moduleCommonSecurityProperties.getOauth2AceAuthenticationGrantType()));
  }

  @Override
  public AuthorizationGrantType getAuthorizationGrantType() {
    return aceAuthorizationGrantTypeSingletonSupplier.get();
  }
}
